class Foo {
    sem_t s1,s2,s3;
public:
    Foo() {
        
        sem_init(&s1,0,1);
        sem_init(&s2,0,0);
        sem_init(&s3,0,0);
    }
    ~Foo() {
        
        sem_destroy(&s1);
        sem_destroy(&s2);
        sem_destroy(&s3);
    }
    void first(function<void()> printFirst) {
        
        // printFirst() outputs "first". Do not change or remove this line.
        sem_wait(&s1);
        printFirst();
        sem_post(&s2);
    }

    void second(function<void()> printSecond) {
        
        // printSecond() outputs "second". Do not change or remove this line.
        sem_wait(&s2);
        printSecond();
        sem_post(&s3);
    }

    void third(function<void()> printThird) {
        
        // printThird() outputs "third". Do not change or remove this line.
        sem_wait(&s3);
        printThird();
        sem_post(&s1);
    }
};
